﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Business.FlowOperation;
using Business.Menu;
using Business;

public partial class GzMain : PageBase
{
    private XtMenuOperation clsMenu = new XtMenuOperation();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(UserName))
            {
                Session["UserName"] = UserName;
                //获取设置标题头
                //string strMsg = "<script>function initWinInfo(){";
                ////设置待办件的地址
                ////  strMsg += "addTab(strFirstUrl,strFirstUrlName);";

                //strMsg += string.Format("loadTitle('divCenter','业务办公区【欢迎您，{0}，今天是{1}】');HideLoading();", UserName, DateTime.Now.ToShortDateString());

                RequestFlowOperation flowOperation = new RequestFlowOperation();
                DataTable dtSource = flowOperation.AppearWorkItem(UserId, "");

                ////获取待接收短消息
                //string strPopContent = "<table>";
                //strPopContent += string.Format("<tr><td><a href=javascript:addTab('MyWindow/TaskInStepList.aspx','接收即时消息')>您有{0}条待办审核</a></td></tr>", dtSource.Rows.Count);
                //strPopContent += "</table>";
                //strMsg += string.Format("loadMsg(\"{0}\");", strPopContent);

                ////针对
                //strMsg += "}</script>";
                GenerateBodyScript();
                //Response.Write(strMsg);
            }
        }
    }
    public void GenerateBodyScript()
    {
        Session["Menu"] = null;
        if (Session["Menu"] == null)
        {
            if (Session["UserID"] != null)
            {
                DataTable dtParent = clsMenu.GenerateParentMenu();

                int i = 0;
                string userid = Convert.ToString(Session["userid"]);
                string strHtml = string.Empty;
                string strFirstUrl = string.Empty;
                string strFirstUrlName = string.Empty;
                for (i = 0; i < dtParent.Rows.Count;i++)
                {
                    DataTable dtChild = clsMenu.GenerateChildMenu(dtParent.Rows[i]["menu_parent_id"].ToString(), userid);
                    if (dtChild.Rows.Count > 0)
                    {
                        if (dtParent.Rows[i]["menu_parent_desc"].ToString()!=null && dtParent.Rows[i]["menu_parent_desc"].ToString()!="") {
                            strHtml += string.Format(@"<li> <a href=""javascript:;""> <span class=""iconfont sider-nav-icon"">&#xe620;</span> <span class=""sider-nav-title"">{1}</span>  <i class=""iconfont"">&#xe642;</i></a>", i, dtParent.Rows[i]["menu_parent_desc"].ToString().Trim());                           
                        }
                    }
                    
                    if (dtChild.Rows.Count>0) {
                        strHtml += "<ul class=\"sider-nav-s\">";
                        for (int j = 0; j < dtChild.Rows.Count; j++)
                        {
                            string strTempUrl = "";
                            strTempUrl = dtChild.Rows[j]["linkhref"].ToString();
                            strTempUrl = strTempUrl.Replace("{CjFlowPage}", SystemConfig.NewActivexAppearUrl);
                            strTempUrl = strTempUrl.Replace("{userid}", userid);

                            if (Session["iid"] != null)
                            {
                                strTempUrl = strTempUrl.Replace("{iid}", Session["iid"].ToString());
                            }
                            
                            strHtml += String.Format(@"<li title='{2}'><a href = ""#"" onclick=""addTab('{1}','{2}')"">{2}</a></li>", j, strTempUrl, dtChild.Rows[j]["menu_child_desc"].ToString().Trim());
                        }
                        strHtml += "</ul>  </li> ";
                    }               
                }
                if (dtParent.Rows.Count > 0)
                {
                    Session["strHtml"] = strHtml;
                }
            }
        }
    }

    /// <summary>
    /// 左侧菜单栏，存贮在Session中
    /// </summary>
    protected string strHtml
    {
        get
        {
            if (Session["strHtml"] != null)
            {
                return Session["strHtml"].ToString();
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
